I'm a doctor, not a mechanic

Legacy:Basic ScriptedPawn Tutorial

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

This is a tutorial that sets up a UT NPC (Monster) via ScriptedPawn.

For a tutorial on using UT2004 Monsters, see A UT2004 Monster Tutorial.

Prerequisites[edit]

You should already be familiar with Bot Pathing, Testing Botplay and Bot Mind. Although we're not dealing with bots, creatures use the same bot path network and perform many similar actions in navigation. You should also be familiar with the properties available on ScriptedPawn.

Overview[edit]

"Scripting" Pawn (UT)s was a common practice for mappers in UT. Whether scripting advanced bot support or setting up monsters to patrol the level, the native AI of the UT Pawns was used in conjuction with AIScripts to create relatively realistic behavior.

This tutorial will show how to implement UT creatures, subclasses of ScriptedPawn.

Tutorial[edit]

This is a general tutorial and guide designed to demonstrate the implementation of several different creatures set to perform several different tasks. After completing this tutorial, you should have a good idea how these AI functions work and be able to experiment combining them in different ways, with different settings, etc.

Setting Up[edit]

You should start with a bot pathed map that is working properly. See also Bot Pathing.

Classes Used[edit]

Retreating[edit]

This is an automatic function rather than an explicit Order. The creature can be made to retreat to a specific spot if hurt or otherwise frightened.

  1. Place a creature in the map and enter a unique Tag that will be used to associate this creature with a HomeBase.
  2. Place a HomeBase somewhere in the map. This will the place the creature will retreat to. Likely places to retreat to include out of the way places, spots "deeper" into the map's layout or objective sequence, or where other creatures can be found to help this creature in combat.
  3. Enter the Tag of the HomeBase to match the creature's Tag.
  4. Decide an appropriate Extend to set for the HomeBase. This is the radius (in UU) that the creature's "home" extends from the HomeBase actor. Note that the creature will only consider themselves at "home" if they are within the Extend and have a line of sight to the HomeBase.
  5. Decide an appropriate LookDir for the HomeBase. This is the direction the creature will face once they are at "home."

Alarm[edit]

Although this is not an explicit Order, Alarm functions can direct a creature to perform complex tasks when an enemy player is first seen. In practical terms, the creature will attempt to perform these tasks at all cost. After the task is complete, the creature will attack the enemy, if still available. After combat, the creature will return to a RestFormation or resume it's normal Orders.

  1. Place a creature in the map and enter a unique AlarmTag that will be used to associate this creature with it's AlarmPoint.
  2. Place an AlarmPoint in a spot that will represent a destination for the task the creature is to perform once "alarmed". This could be a spot near other creatures to help in combat, it could be an actual alarm trigger (a switch the creature activates to set off an audible alarm sound), or it could be a better tactical position to attack from. While the specific tasks the creature is to perform can vary, the main idea is that it will travel to this AlarmPoint once "alarmed".
  3. You may add additional AlarmPoints as long as they all have a unique Tag. Place as many additional AlarmPoints as you like. These will make the creature travel from the first AlarmPoint to the next in a series until the last AlarmPoint is reached.
  4. Enter the Tag of the next AlarmPoint in the NextAlarm property of this AlarmPoint. Move on to the next AlarmPoint in the series and continue to enter the NextAlarm property until all are properly associated.
  5. Decide if the creature should perform a specific animation sequence when this AlarmPoint is reached. If so, enter the name of the animation sequence in the AlarmAnim property of the AlarmPoint. A list of animation sequece names can be found in the Mesh Browser. Note that animation sequences are specific to the creature used.
  6. Decide if the creature should play a specific sound while at this AlarmPoint. Enter the sound in the AlarmSound property of the AlarmPoint.
  7. If no AlarmAnim is used, decide if the creature should pause and play default waiting animations when this AlarmPoint is reached. Enter the time to pause (in seconds) in the PauseTime property on the AlarmPoint.
  8. The creature can be made to shoot at any actor when this AlarmPoint is reached. Enter the Tag of the actor in the ShootTarget property on this AlarmPoint.

Note: The AlarmPoint actor has many other properties with which to adjust the creature's behavior. In conjunction with other AlarmPoints, Triggers, etc., the creature can be made to perform complex behavior once a player enemy is detected. See also AlarmPoint. (See also Steve Polge's guide linked to at the bottom of this page. Some properties on the AlarmPoint page here on the wiki are suspect.)

Waiting[edit]

This is the default Order. The creature will wait near its location, sometimes randomly wandering, until a player enemy is seen to attack. After combat, the creature will return to a waiting state.

  1. Place a creature in the map and enter "Waiting" in the Orders property, if it isn't already set.
  2. That's it. You may want to rotate the creature to face a particular direction at match start, but after a short while, it will wander and change it's location and rotation on its own.

Ambushing[edit]

The creature will find a place to wait in ambush for a player to attack. Once combat is over, the creature will find another spot to ambush from and again wait for a player to attack.

  1. Place a creature in the map and enter "Ambushing" in the Orders property.
  2. Enter a unique OrderTag that will be used to associate this creature with it's AmbushPoints.
  3. Place AmbushPoints in the map at places where the creature can reach, can watch out for players, and hopefully can attack from with some element of suprise. A ledge, a side passage or a hole are likely places to Ambush from. Place as many as you like.
  4. Enter the Tag of these AmbushPoints to match your creature's OrderTag. This will associate the creature to these AmbushPoints.
  5. Decide whether to set bFixedStart to true on the creature or not. If true, the creature will always start the match at the placed position and travel to a random AmbushPoint to ambush players. If false, the creature will be teleported to a random AmbushPoint at match start.
  6. Decide whether to set bSniping to true on the various AmbushPoints. If true, the creature will likely snipe from that position when it sees a player to attack.
  7. Adjust the SightRadius on the various AmbushPoints, if necessary. This is the radius (in UU) that will be used by the creature when it is waiting to ambush at this point.

Patroling[edit]

The creature will move from spot to spot in a patrol route until a player enemy is seen to attack. After combat, the creature will return to the patrol route and continue to patrol.

  1. Place a creature in your map and enter "Patroling" in the Orders property.
  2. Enter a unique OrderTag that will be used to match this creature with a starting PatrolPoint. (suggested name, "Patrol1")
  3. Place a series of PatrolPoints in the map to define the patroling route for this creature. The creature will follow the normal path network to get from PatrolPoint to PatrolPoint, so you do not need to define each corner. Instead, find places that might be good to have this creature pause while patroling. A room, a lookout, a switchback or dead end are likely places to place PatrolPoints. Place as many as you like.
  4. Enter the Tag of the first PatrolPoint to match the creature's OrderTag. This will associate the creature with this patrol route and further associate this PatrolPoint as the creature's start.
  5. Enter the NextPatrol property of this PatrolPoint to match the Tag of the next PatrolPoint in the series along this patrol route. Enter the Tag of the next PatrolPoint to match.
  6. Repeat 4-5 until the patrol route is defined. Match the NextPatrol property of the last PatrolPoint with the Tag of the first PatrolPoint in the route to complete the loop.
  7. Decide whether to set bFixedStart to true on the creature. If true, the creature will always start the match at the placed position and travel to the starting PatrolPoint. If false, the creature will be teleported to the starting PatrolPoint at match start.
  8. Decide whether to set bDelayedPatrol to true on the creature. If true, the creature will wait at the placed location until it is triggered before it will travel to the first PatrolPoint and begin the patrol.
  9. Decide whether the creature should perform a specific animation sequence while at this PatrolPoint. The creature can be made to play an animation, pause using standard waiting animations or neither and simply move on to the next PatrolPoint. If a specific animation sequence is desired, enter the name of the sequence in the PatrolAnim property of the PatrolPoint. A list of animation sequences can be found in the Mesh Browser. Note that animation sequences are specific to the creature used.
  10. If an animation sequence is used, the creature can be made to loop the animation sequence a number of times. Enter the desired number of sequence loops in the NumAnims property of the PatrolPoint.
  11. Decide whether the creature should play a specific sound while performing an animation sequence at this PatrolPoint. Enter the sound in the PatrolSound property of the PatrolPoint.
  12. If no PatrolAnim is defined but a pause is desired, enter the number of seconds to pause in the PauseTime properties of the PatrolPoint.

Guarding[edit]

The creature will guard an item. It will stay at its placed location until an enemy player is seen, when it will challenge the player to combat. After combat, the creature will return to the placed location and continue to guard the item. If the item is touched, the creature will consider the "toucher" an enemy.

  1. Place a creature in the map and set its Order property to "Guarding". It's a good idea to place the creature near the item to be guarded, or at least within a line of sight to that item or the area surrounding the item.
  2. Enter a unique Tag on the item that will associate it with the creature guarding it. Match the creature's OrderTag to the Tag of the item.

PawnSpecific Orders[edit]

Some individual creatures have unique Orders or functions. See also the ScriptedPawn subclasses for the various creatures.

CreatureFactory and SpawnPoints[edit]

CreatureFactory is a subclass of ThingFactory. SpawnPoints are associated to factories to provide a suitable place to spawn an actor. CreatureFactories are specifically designed to spawn creatures in-game and give appropriate settings to various properties.

  1. Place a CreatureFactory in the map. Thing and CreatureFactories can either be triggered externally or activated via Touch, just like a Trigger. For this tutorial, place the CreatureFactory in a spot where a player is likely to walk by. We will set this CreatureFactory to spawn the creature when touched.
  2. Place a SpawnPoint somewhere in the map that will allow access to the bot path network and give enough space for the creature to be spawned. Also rotate the SpawnPoint to a good orientation for the creature to be spawned.
  3. Enter a unique Tag on the SpawnPoint that will associate it with the CreatureFactory. Match the CreatureFactory's Tag to the SpawnPoint Tag.
  4. Place as many additional SpawnPoints as you like, up to a total of 16. Make sure their Tags all match the Tag of the CreatureFactory. Spawned creatures will appear randomly at one of these SpawnPoints.
  5. Set the ThingFactory->Prototype property on the CreatureFactory to the desired creature to spawn.
  6. Set the ThingFactory->MaxItems property on the CreatureFactory to the maximum number of creatures this factory will allow in game at one time.
  7. Set the ThingFactory->Capacity property on the CreatureFactory to the maximum number of total creatures to spawn. After this number is reached, the factory will shut down. A value of -1 here indicates the factory should never shut down.
  8. Set the ThingFactory->Interval property to the (average) number of seconds to wait before this factory is ready to spawn the next creature. Note that spawning several creature with an interval of zero will likely cause a "hiccup", where the engine stalls momentarily while spawning. Set the interval to something small instead, like 0.1
  9. Set the ThingFactory->bOnlyPlayerTouched property on the CreatureFactory to true. For this tutorial, we want the player to trigger the factory when it touches it, but we don't want other creatures to trigger it. If true, only player pawns are able to activate this factory.
  10. Decide if the ThingFactory->bCovert property on the CreatureFactory should be set to false. It is set to true by default. If true, the creature will only be spawned if a player is unable to see it spawned, otherwise the factory will wait. If your SpawnPoint is in plain sight but you'd like creatures to spawn at it even if a player sees the creature appear from (seemingly) nowhere, this could be set to false.
  11. Decide if the ThingFactory->bStoppable property on the CreatureFactory should be set to true. If true, the factory will spawn creatures if Touched (or triggered) and will stop spawning creatures when it is unTouched.
  12. Set the CreatureFactory->Orders, OrderTag and AlarmTag properties on the CreatureFactory to those desired property settings for the spawned creatures.
  13. If the game is set to CoOp mode, decide if extra creatures should be spawned from this factory. Enter the number of extra creatures to spawn in the AddedCoopCapacity property on the CreatureFactory.

NOTE: Creatures spawned from a given SpawnPoint will have their Event set to match the Tag of the CreatureFactory (and the SpawnPoint). That way, once the creature is killed, it will automatically trigger a new creature to be spawned.

External Links[edit]

Steve Polge's Docs[edit]

Matthias Worch's Tutorials[edit]

Matthias Worch, who worked on the Unreal 2 team, has written a couple of tutorials that are highly useful. He's even provided a small demo level.

Set up dialog and AI scripting for a level and Create a basic AI script are the articles of interest here.

Related Topics[edit]

Discussion[edit]

SuperApe: This tutorial needs to be written. The external links above might be used to help write an original tutorial. This tutorial should at least cover Patroling and Ambushing.

SuperApe: I've been working with the original ScriptedPawn code from UT. I believe I know how all this works, but I don't have UT. If no one writes this soon, I will probably take a crack at it, based on what I'm seeing in the code.

SuperApe: Although I do not have UT, I am now familiar with the code that these AI systems ran on, having looked at the code for ScriptedPawn. I am writing this tutorial with the stipulation that it may not be complete or completely accurrate. However, it should be close at the very least.

SuperApe: Finished the tutorial. Let me know if there are any problems.